// This file was generated automatically from xinerama.xml.

package xgb

const XINERAMA_MAJOR_VERSION = 1
const XINERAMA_MINOR_VERSION = 1

type XineramaScreenInfo struct {
	XOrg   int16
	YOrg   int16
	Width  uint16
	Height uint16
}

func getXineramaScreenInfo(b []byte, v *XineramaScreenInfo) int {
	v.XOrg = int16(get16(b[0:]))
	v.YOrg = int16(get16(b[2:]))
	v.Width = get16(b[4:])
	v.Height = get16(b[6:])
	return 8
}

func (c *Conn) bytesXineramaScreenInfoList(list []XineramaScreenInfo, count int) []byte {
	b0 := make([]byte, 8*count)
	for k := 0; k < count; k++ {
		b := b0[k*8:]
		put16(b[0:], uint16(list[k].XOrg))
		put16(b[2:], uint16(list[k].YOrg))
		put16(b[4:], list[k].Width)
		put16(b[6:], list[k].Height)
	}
	return c.bytesPadding(b0)
}

const OpcodeXineramaQueryVersion = 0

func (c *Conn) XineramaQueryVersionRequest(
	Major byte, Minor byte) *Cookie {
	b := make([]byte, 8)
	put16(b[2:], 2)
	b[0] = c.getExtensionOpcode("XINERAMA")
	b[1] = 0
	b[4] = Major
	b[5] = Minor
	return c.sendRequest(true, b)
}

func (c *Conn) XineramaQueryVersion(
	Major byte, Minor byte) (*XineramaQueryVersionReply, error) {
	return c.XineramaQueryVersionReply(c.XineramaQueryVersionRequest(Major, Minor))
}

type XineramaQueryVersionReply struct {
	Major uint16
	Minor uint16
}

func (c *Conn) XineramaQueryVersionReply(cookie *Cookie) (*XineramaQueryVersionReply, error) {
	b, error := c.waitForReply(cookie)
	if error != nil {
		return nil, error
	}
	v := new(XineramaQueryVersionReply)
	v.Major = get16(b[8:])
	v.Minor = get16(b[10:])
	return v, nil
}

const OpcodeXineramaGetState = 1

func (c *Conn) XineramaGetStateRequest(
	Window Id) *Cookie {
	b := make([]byte, 8)
	put16(b[2:], 2)
	b[0] = c.getExtensionOpcode("XINERAMA")
	b[1] = 1
	put32(b[4:], uint32(Window))
	return c.sendRequest(true, b)
}

func (c *Conn) XineramaGetState(
	Window Id) (*XineramaGetStateReply, error) {
	return c.XineramaGetStateReply(c.XineramaGetStateRequest(Window))
}

type XineramaGetStateReply struct {
	State  byte
	Window Id
}

func (c *Conn) XineramaGetStateReply(cookie *Cookie) (*XineramaGetStateReply, error) {
	b, error := c.waitForReply(cookie)
	if error != nil {
		return nil, error
	}
	v := new(XineramaGetStateReply)
	v.State = b[1]
	v.Window = Id(get32(b[8:]))
	return v, nil
}

const OpcodeXineramaGetScreenCount = 2

func (c *Conn) XineramaGetScreenCountRequest(
	Window Id) *Cookie {
	b := make([]byte, 8)
	put16(b[2:], 2)
	b[0] = c.getExtensionOpcode("XINERAMA")
	b[1] = 2
	put32(b[4:], uint32(Window))
	return c.sendRequest(true, b)
}

func (c *Conn) XineramaGetScreenCount(
	Window Id) (*XineramaGetScreenCountReply, error) {
	return c.XineramaGetScreenCountReply(c.XineramaGetScreenCountRequest(Window))
}

type XineramaGetScreenCountReply struct {
	ScreenCount byte
	Window      Id
}

func (c *Conn) XineramaGetScreenCountReply(cookie *Cookie) (*XineramaGetScreenCountReply, error) {
	b, error := c.waitForReply(cookie)
	if error != nil {
		return nil, error
	}
	v := new(XineramaGetScreenCountReply)
	v.ScreenCount = b[1]
	v.Window = Id(get32(b[8:]))
	return v, nil
}

const OpcodeXineramaGetScreenSize = 3

func (c *Conn) XineramaGetScreenSizeRequest(
	Window Id, Screen uint32) *Cookie {
	b := make([]byte, 12)
	put16(b[2:], 3)
	b[0] = c.getExtensionOpcode("XINERAMA")
	b[1] = 3
	put32(b[4:], uint32(Window))
	put32(b[8:], Screen)
	return c.sendRequest(true, b)
}

func (c *Conn) XineramaGetScreenSize(
	Window Id, Screen uint32) (*XineramaGetScreenSizeReply, error) {
	return c.XineramaGetScreenSizeReply(c.XineramaGetScreenSizeRequest(Window, Screen))
}

type XineramaGetScreenSizeReply struct {
	Width  uint32
	Height uint32
	Window Id
	Screen uint32
}

func (c *Conn) XineramaGetScreenSizeReply(cookie *Cookie) (*XineramaGetScreenSizeReply, error) {
	b, error := c.waitForReply(cookie)
	if error != nil {
		return nil, error
	}
	v := new(XineramaGetScreenSizeReply)
	v.Width = get32(b[8:])
	v.Height = get32(b[12:])
	v.Window = Id(get32(b[16:]))
	v.Screen = get32(b[20:])
	return v, nil
}

const OpcodeXineramaIsActive = 4

func (c *Conn) XineramaIsActiveRequest() *Cookie {
	b := make([]byte, 4)
	put16(b[2:], 1)
	b[0] = c.getExtensionOpcode("XINERAMA")
	b[1] = 4
	return c.sendRequest(true, b)
}

func (c *Conn) XineramaIsActive() (*XineramaIsActiveReply, error) {
	return c.XineramaIsActiveReply(c.XineramaIsActiveRequest())
}

type XineramaIsActiveReply struct {
	State uint32
}

func (c *Conn) XineramaIsActiveReply(cookie *Cookie) (*XineramaIsActiveReply, error) {
	b, error := c.waitForReply(cookie)
	if error != nil {
		return nil, error
	}
	v := new(XineramaIsActiveReply)
	v.State = get32(b[8:])
	return v, nil
}

const OpcodeXineramaQueryScreens = 5

func (c *Conn) XineramaQueryScreensRequest() *Cookie {
	b := make([]byte, 4)
	put16(b[2:], 1)
	b[0] = c.getExtensionOpcode("XINERAMA")
	b[1] = 5
	return c.sendRequest(true, b)
}

func (c *Conn) XineramaQueryScreens() (*XineramaQueryScreensReply, error) {
	return c.XineramaQueryScreensReply(c.XineramaQueryScreensRequest())
}

type XineramaQueryScreensReply struct {
	Number     uint32
	ScreenInfo []XineramaScreenInfo
}

func (c *Conn) XineramaQueryScreensReply(cookie *Cookie) (*XineramaQueryScreensReply, error) {
	b, error := c.waitForReply(cookie)
	if error != nil {
		return nil, error
	}
	v := new(XineramaQueryScreensReply)
	v.Number = get32(b[8:])
	offset := 32
	v.ScreenInfo = make([]XineramaScreenInfo, int(v.Number))
	for i := 0; i < int(v.Number); i++ {
		offset += getXineramaScreenInfo(b[offset:], &v.ScreenInfo[i])
	}
	return v, nil
}
